<cfcomponent displayname="announcementsGateway" output="false">
	<cffunction name="init" access="public" output="false" returntype="trac_fu.model.announcements.announcementsGateway">
		<cfargument name="dsn" type="string" required="true" />
		<cfset variables.dsn = arguments.dsn />
		<cfreturn this />
	</cffunction>
	
	<cffunction name="getByAttributes" access="public" output="false" returntype="query">
		<cfargument name="id" type="string" required="false" />
		<cfargument name="title" type="string" required="false" />
		<cfargument name="body" type="string" required="false" />
		<cfargument name="projectidfk" type="string" required="false" />
		<cfargument name="useridfk" type="string" required="false" />
		<cfargument name="posted" type="date" required="false" />
		<cfargument name="orderby" type="string" required="false" />
		
		<cfset var qList = "" />		
		<cfquery name="qList" datasource="#variables.dsn#">
			SELECT
				id,
				title,
				body,
				projectidfk,
				useridfk,
				posted
			FROM	announcements
			WHERE	0=0
		
		<cfif structKeyExists(arguments,"id") and len(arguments.id)>
			AND	id = <cfqueryparam value="#arguments.id#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"title") and len(arguments.title)>
			AND	title = <cfqueryparam value="#arguments.title#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"body") and len(arguments.body)>
			AND	body = <cfqueryparam value="#arguments.body#" CFSQLType="cf_sql_longvarchar" />
		</cfif>
		<cfif structKeyExists(arguments,"projectidfk") and len(arguments.projectidfk)>
			AND	projectidfk = <cfqueryparam value="#arguments.projectidfk#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"useridfk") and len(arguments.useridfk)>
			AND	useridfk = <cfqueryparam value="#arguments.useridfk#" CFSQLType="cf_sql_varchar" />
		</cfif>
		<cfif structKeyExists(arguments,"posted") and len(arguments.posted)>
			AND	posted = <cfqueryparam value="#arguments.posted#" CFSQLType="cf_sql_date" />
		</cfif>
		<cfif structKeyExists(arguments, "orderby") and len(arguments.orderBy)>
			ORDER BY #arguments.orderby#
		</cfif>
		</cfquery>
		
		<cfreturn qList />
	</cffunction>

</cfcomponent>